<?php

App::uses('Helper', 'View');

class AppHelper extends Helper {

    public function value($options = array(), $field = null, $key = 'value') {
        if (!isset($this->request->data['Cake']) && isset($this->Auth)) {
            global $CONTROLLER;
            
            $match = substr(str_replace(array('data', '[', ']'), array('', '.', ''), $options['name']), 1);
            if (strpos($match, ".") !== false) {
                list($model, $field) = explode(".", $match);

                if (isset($this->request->data[$model][$field])) {
                    $field_data = $CONTROLLER->getFieldData($match, 'fields');
                    $this->request->data[$model][$field] = $CONTROLLER->getFieldPresentationObj($field_data, $this->request->data[$model][$field])->loadDbQuery();
                }
            }
        }

        return parent::value($options, $field, $key);
    }

}
